import 'package:dio_log/overlay_draggable_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_li_ke_jie/constant/app_constant.dart';
import 'package:flutter_li_ke_jie/style/common_color.dart';
import 'package:flutter_li_ke_jie/ui/home/home_model.dart';
import 'package:flutter_li_ke_jie/ui/home/index_fragment.dart';
import 'package:flutter_li_ke_jie/ui/home/ji_su_dai_fragment.dart';
import 'package:flutter_li_ke_jie/ui/home/my_fragment.dart';
import 'package:flutter_li_ke_jie/ui/home/vip_fragment.dart';
import 'package:flutter_li_ke_jie/ui/home/vip_play_fragment.dart';
import 'package:flutter_li_ke_jie/utils/img_util.dart';
import 'package:flutter_li_ke_jie/utils/sputil.dart';

import '../../core/interface/common_interface.dart';

///home
class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with CommonInterface<HomeModel>{
  late HomeModel homeModel;
  @override
  Widget build(BuildContext context) {
    homeModel = model(context);
    return Scaffold(
      body:_getCurrentPageWidget(homeModel.currentIndex),
      bottomNavigationBar:BottomNavigationBar(
        currentIndex: homeModel.currentIndex,
        onTap: (index){
          homeModel.switchIndex(index);
        },
        type: BottomNavigationBarType.fixed,
        items: _bottomNavs(),
      ),
      floatingActionButton: showDebugBtn(context,btnColor: Colors.blue),
    );
  }

  //底部导航
  List<BottomNavigationBarItem> _bottomNavs(){
    return [
      BottomNavigationBarItem(
        icon:Image.asset(ImageUtil.loadLocalImg("icon_hp_unclick.png"),height: 24,width: 24,),
        activeIcon:Image.asset(ImageUtil.loadLocalImg("icon_hp.png"),height: 24,width: 24),
        label: "首页",
      ),
      BottomNavigationBarItem(
        icon:Image.asset(ImageUtil.loadLocalImg("icon_speed_loan_unclick.png"),height: 24,width: 24,),
        activeIcon:Image.asset(ImageUtil.loadLocalImg("icon_speed_loan.png"),height: 24,width: 24),
        label: "极速贷",
      ),
      BottomNavigationBarItem(
          icon:Image.asset(ImageUtil.loadLocalImg("icon_vip_unclick.png"),height: 24,width: 24,),
          activeIcon:Image.asset(ImageUtil.loadLocalImg("icon_vip.png"),height: 24,width: 24),
          label:"会员"
      ),
      BottomNavigationBarItem(
          icon:Image.asset(ImageUtil.loadLocalImg("icon_me_unclick.png"),height: 24,width: 24,),
          activeIcon:Image.asset(ImageUtil.loadLocalImg("icon_me.png"),height: 24,width: 24),
          label:"我的"
      )
    ];
  }

  //底部切换部署
  Widget _getCurrentPageWidget(int index){
    switch(index){
      case 0:{
        return const IndexFragment();
      }
      case 1:{
        return const JiSuDaiFragment();
      }
      case 2:{
        //查询用户的vip状态
        int? vipState = SPUtil.getVipState();
        if(vipState!=null&&vipState==1){
          return const VipPlayFragment();
        }else{
          return const VipFragment();
        }
      }
      case 3:{
        return const MyFragment();
      }
      default:return const IndexFragment();
    }
  }
}
